/*
* Copyright 2017 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-service-wechatpush
*
* @File name : ConsumeCouponHandler.java
*
* @Author : Administrator
*
* @Date : 2017年8月4日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2017年8月4日    Administrator    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/
	
package com.yonyou.gmmc.service.wechatpush.event.handler;

import org.marketing.common.dto.EventDataDTO;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocol;
import org.marketing.common.event.BizEvent;
import org.marketing.common.event.EventConsumeCouponDTO;
import org.marketing.common.util.MapConverUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yonyou.gmmc.service.wechatpush.event.exception.PushException;
import com.yonyou.gmmc.service.wechatpush.event.service.ConsumeCouponService;
import com.yonyou.gmmc.service.wechatpush.util.SpringUtil;

/**
*
* @author Administrator
* @date 2017年8月4日
*/

public class ConsumeCouponHandler extends AbstractEventHandle {
    private static Logger logger = LoggerFactory.getLogger(ConsumeCouponHandler.class);
    
    private ConsumeCouponService consumeCouponService;
    
    @Override
    protected String getHandleInfo() {
        return "处理卡券核销模板节点";
    }

    
    /**
     * 主要进行数据转换
     */
    @Override
    protected EventConsumeCouponDTO preCheck(BizEvent event) {
        EventConsumeCouponDTO o = new EventConsumeCouponDTO();
        try {
            o = (EventConsumeCouponDTO) MapConverUtil.map2PO(event.getEventData(), o);
            logger.info(o.toString());
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            this.backInfo = "eventData中的业务数据不能识别：" + e.getMessage();
            throw new PushException(PushException.EVENT_CONVERT_FAILD,"eventData中的业务数据不能识别");
        }
        return o;
    }

    /**
     * 模板推送处理的逻辑
     */
    @Override
    protected boolean push(EventDataDTO eventData) throws PushException{
        consumeCouponService=(ConsumeCouponService)SpringUtil.getBean("consumeCouponService");
        WeChatMessageProtocol t=consumeCouponService.getWXTemplate((EventConsumeCouponDTO)eventData);
        this.sendNotify(t);
        return false;
    }

    @Override
    protected void afterPush() {
        // TODO Auto-generated method stub
    }

}
